package com.apes.scm.masterdata.product.repository;

import com.apes.framework.jpa.repository.CustomRepository;
import com.apes.scm.masterdata.product.model.ProductUom;
import com.apes.scm.masterdata.product.model.ProductUomCategory;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

/**
 * @author xul
 * @create 2018-02-06 16:47
 */
public interface ProductUomRepository extends CustomRepository<ProductUom, Long> {

    /**按商品计量单位类别查找对应的计量单位**/
    List<ProductUom> findAllByUomCategory(ProductUomCategory category);

    @Query("SELECT T FROM ProductUom T WHERE 1 = 1 and name = :name and uomCategory.id = :uomCategory ")
    ProductUom findProductUom(@Param("name") String name, @Param("uomCategory") String uomCategory);

    @Query(value = "SELECT * FROM mas_product_uom WHERE uom_category_id = :id AND FACTOR = 1 AND VALID = 1 ",nativeQuery = true)
    ProductUom findByProductIdFactorMin(@Param("id") String id);

    @Query(value = "SELECT * FROM mas_product_uom WHERE uom_category_id = :id AND transfer_First = 1 and VALID = 1 and rownum = 1 ",nativeQuery = true)
    ProductUom findByProductId(@Param("id") String id);

    @Query(value = "SELECT * FROM mas_product_uom WHERE uom_category_id = :id AND purchase_First = 1 and VALID = 1 and rownum = 1 ",nativeQuery = true)
    ProductUom findBypurchaseUom(@Param("id") String id);
}
